package com.yuandian.customer.perception.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuandian.api.customer_perception.po.HighFrequencyAlarmParams;
import com.yuandian.api.customer_perception.vo.HighFrequencyAlarmVo;
import com.yuandian.api.customer_perception.vo.StatTypeVo;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.customer.perception.mapper.HighFrequencyAlarmMapper;
import com.yuandian.customer.perception.service.IHighFrequencyAlarmService;
import com.yuandian.utils.PageDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 说明：高频告警service实现
 * @Author yanjun
 * @Date 2021/5/10 8:43
 */
@Service
public class HighFrequencyAlarmServiceImpl implements IHighFrequencyAlarmService {

    @Autowired
    private HighFrequencyAlarmMapper highFrequencyAlarmMapper;

    /**
     * 查询高频告警列表
     * @param params 高频告警请求对象
     * @return 通用分页对象
     */
    //@DS("khgzData")
    @Override
    public PageDataInfo queryHighFrequencyAlarmList(HighFrequencyAlarmParams params) {
        Page<HighFrequencyAlarmVo> page = new Page<>(params.getPageNum(), params.getPageSize());

        List<HighFrequencyAlarmVo> list = highFrequencyAlarmMapper.queryHighFrequencyAlarmList(params, page);
        if (null != list && list.size() > 0) {
            list.forEach(item -> {
                if (item.getAlarmRateTmp() != null && item.getAlarmRateTmp() >= 100) { item.setAlarmRateTmp(100.0); }
                item.handleNumberFormat();
            });
        }


        return new PageDataInfo(page, list);
    }


    //@DS("khgzData")
    @Override
    public R queryStatTypeList() {
        List<StatTypeVo> typeVos = highFrequencyAlarmMapper.queryStatTypeList();
        return R.ok(typeVos);
    }
}
